package com.health.controller.checkGroup;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.entity.PageResult;
import com.health.entity.QueryPageBean;
import com.health.entity.Result;
import com.health.pojo.CheckGroup;
import com.health.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * @Classname CheckGroupController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/16 10:38
 * @Author RainGrd
 */
@RestController
@RequestMapping("/checkGroup")
@Slf4j
public class CheckGroupController {


    @Reference
    private CheckGroupService checkGroupService;

    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return checkGroupService.queryCheckGroupPage(queryPageBean);
    }


    /**
     * 用于保存预约管理
     *
     * @param checkGroup
     * @return
     */
    @RequestMapping("/add.do")
    public Result add(@RequestBody CheckGroup checkGroup, Integer[] checkItemIds) {
        log.info("checkGroup:{}", checkGroup);

        return checkGroupService.saveCheckGroup(checkGroup, checkItemIds);
    }

    @RequestMapping("/findCheckItemIdsByCheckGroupId.do")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer id) {
        log.info("查询当前检查组包含的所有检查项id:{}", id);
        return checkGroupService.queryCheckItemIdsByCheckGroupId(id);
    }

    /**
     * 根据id删除预约管理
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete.do")
    public Result delete(@RequestParam Integer id) {
        log.info("要删除的预约管理id:{}", id);
        return checkGroupService.clearCheckGroup(id);
    }

    @RequestMapping("/edit.do")
    public Result edit(@RequestBody CheckGroup checkGroup, Integer[] checkItemIds) {
        log.info("要编辑的检查组对象:{}", checkGroup);
        log.info("要编辑的检查组对象数组:{}", Arrays.asList(checkItemIds));
        return checkGroupService.editCheckGroup(checkGroup, checkItemIds);
    }

    @RequestMapping("/findAll.do")
    public Result findAll(){
        return checkGroupService.queryAll();
    }

}
